package cosc617_blackteam;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Laura
 * Iterates through all of the empty tables
 */
public class EmptyTableIterator implements Iterator<Table> {

	private ArrayList<Table> tableList;
	private int index;
	
	public EmptyTableIterator(ArrayList<Table> tableList){
		this.tableList = tableList;
		index = 0;
	}
	@Override
	public boolean hasNext() {
		while ( index < tableList.size()){
			Table table = tableList.get(index);
			if(table.isEmpty()) //will be true if table is empty
				return true;
			index++;
		}
		return false;
	}

	@Override
	public Table next() {
		Table output =  tableList.get(index);
			index++;
		return output; //if not found will return null
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}

}
